package net.hn.hnms.biz.safety.fire.controller.feign;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import net.hn.hnms.biz.api.safety.monitor.model.BaseSensorCoordDto;
import net.hn.hnms.biz.safety.domain.SensorInfoPo;
import net.hn.hnms.biz.safety.mapper.SensorInfoMapper;
import net.hn.hnms.sys.common.core.utils.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 远程调用火灾防治
 */
//@ApiIgnore
@RestController
@RequestMapping("/remoteHzfz")
@Validated
public class RemoteHzfzController {
    /**
     * 束管检测基本信息Mapper
     */
    @Resource
    private SensorInfoMapper sensorInfoMapper;

    /**
     * 远程调用束管监测BaseSensorTable表所有信息
     */
    @GetMapping("getSgjcBaseSensorTableAllList")
    public List<BaseSensorCoordDto> getSgjcBaseSensorTableAllList(String mineCode, String companyCode){
        LambdaQueryWrapper<SensorInfoPo> sensorInfoPoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        sensorInfoPoLambdaQueryWrapper.eq(StringUtils.isNotBlank(mineCode), SensorInfoPo::getMineCode, mineCode);
        List<SensorInfoPo> sensorInfoPos = sensorInfoMapper.selectList(sensorInfoPoLambdaQueryWrapper);
        if (sensorInfoPos.isEmpty()) {
            return new ArrayList<>();
        }
        return sensorInfoPos.stream().map(t -> {
            BaseSensorCoordDto baseSensorCoordDto = new BaseSensorCoordDto();
            //传感器编码
            baseSensorCoordDto.setPointCode(t.getPointCode());
            //传感器名称
            baseSensorCoordDto.setLocation(t.getPointMonitorLocation());
            //传感器类型编码
            baseSensorCoordDto.setSensorTypeCode(t.getPointTypeCode());
            //传感器类型名称
            baseSensorCoordDto.setSensorTypeName("束管");
            //x
            baseSensorCoordDto.setXCoordinate(t.getXCoordinate());
            //y
            baseSensorCoordDto.setYCoordinate(t.getYCoordinate());
            //z
            baseSensorCoordDto.setZCoordinate(t.getZCoordinate());
            return baseSensorCoordDto;
        }).collect(Collectors.toList());
    }
}